package com.pew.tasktimer.domain.report;

import org.testng.annotations.Test;

import com.pew.tasktimer.domain.Task;
import com.pew.tasktimer.domain.report.ReportSumation.GROUP_BY;

public class ReportSumationTest {

  //@Test
  public void addReportSumation() {
    throw new RuntimeException("Test not implemented");
  }

  //@Test
  public void addReportSumations() {
    throw new RuntimeException("Test not implemented");
  }

  //@Test
  public void addTask() {
    throw new RuntimeException("Test not implemented");
  }

  @Test
  public void getGroupBy() {
    ReportSumation lReport = new ReportSumation();
    
    assert (lReport.getGroupBy() == ReportSumation.GROUP_BY.NOT_SET);
  }

  @Test
  public void getGroupingFromTask() {
    ReportSumation lReport = new ReportSumation();
    Task lTask = new Task();
    lTask.startTimer();
    lTask.stopTimer(lTask.getClStartTime() + 80000);
    
    //No grouping set
    String lStrGrouping = lReport.getGroupingFromTask(lTask);
    String lStrExpected = "";
    
    assert (lStrExpected.equals(lStrGrouping));
    
    //Month day year
    lReport.setGrouping(ReportSumation.GROUP_BY.MONTH_DAY_YEAR);
    lStrExpected = lTask.getCiStopYear() + "-" + lTask.getCiStopMonth() + "-" + lTask.getCiStopDayOfMonth();
    lStrGrouping = lReport.getGroupingFromTask(lTask);
    
    assert (lStrExpected.equals(lStrGrouping));
    
    //Project
    lReport.setGrouping(ReportSumation.GROUP_BY.PROJECT);
    lStrExpected = lTask.getProject();
    lStrGrouping = lReport.getGroupingFromTask(lTask);
    assert (lStrExpected.equals(lStrGrouping));
    
  //Month year
    lReport.setGrouping(ReportSumation.GROUP_BY.MONTH_YEAR);
    lStrExpected = lTask.getCiStopYear() + "-" + lTask.getCiStopMonth();
    lStrGrouping = lReport.getGroupingFromTask(lTask);
    
    assert (lStrExpected.equals(lStrGrouping));
  }
  
  @Test
  public void sumNoGroup() {
    ReportSumation lReport = new ReportSumation();
    Task lTask = new Task();
    lTask.startTimer();
    lTask.stopTimer(lTask.getClStartTime() + 80000);
    
    double ldTestSum = lTask.getCfDiffHourF();
    
    //No grouping set
    boolean isAccepted = lReport.addTask(lTask);
    
    assert (isAccepted);
    assert (lReport.getCiCount() == 1);
    assert (lReport.getCdSum() == ldTestSum);
    
    lTask = new Task();
    lTask.startTimer();
    lTask.stopTimer(lTask.getClStartTime() + 2451378);
    ldTestSum += lTask.getCfDiffHourF();
    
    isAccepted = lReport.addTask(lTask);
    
    assert (isAccepted);
    assert (lReport.getCiCount() == 2);
    assert (lReport.getCdSum() == ldTestSum);
  }
  
  @Test
  public void sumMonthDayGroup() {
    ReportSumation lReport = new ReportSumation();
    lReport.setGrouping(GROUP_BY.MONTH_DAY_YEAR);
    Task lTask = new Task();
    lTask.startTimer();
    lTask.stopTimer(lTask.getClStartTime() + 80000);
    
    double ldTestSum = lTask.getCfDiffHourF();
    
    boolean isAccepted = lReport.addTask(lTask);
    
    assert (isAccepted);
    assert (lReport.getCiCount() == 1);
    assert (lReport.getCdSum() == ldTestSum);
    
    lTask = new Task();
    lTask.startTimer();
    lTask.stopTimer(lTask.getClStartTime() + 851378);
    ldTestSum += lTask.getCfDiffHourF();
    
    isAccepted = lReport.addTask(lTask);
    
    assert (isAccepted);
    assert (lReport.getCiCount() == 2);
    assert (lReport.getCdSum() == ldTestSum);
  }
  
  @Test
  public void sumProjectGroup() {
	    ReportSumation lReport = new ReportSumation();
	    lReport.setGrouping(GROUP_BY.PROJECT);
	    Task lTask = new Task();
	    lTask.startTimer();
	    lTask.stopTimer(lTask.getClStartTime() + 80000);
	    lTask.setcStrProject("testprj1");
	    
	    double ldTestSum = lTask.getCfDiffHourF();
	    
	    //No grouping set
	    boolean isAccepted = lReport.addTask(lTask);
	    
	    assert (isAccepted);
	    assert (lReport.getCiCount() == 1);
	    assert (lReport.getCdSum() == ldTestSum);
	    
	    lTask = new Task();
	    lTask.startTimer();
	    lTask.stopTimer(lTask.getClStartTime() + 851378);
	    lTask.setcStrProject("testprj1");
	    ldTestSum += lTask.getCfDiffHourF();
	    
	    isAccepted = lReport.addTask(lTask);
	    
	    assert (isAccepted);
	    assert (lReport.getCiCount() == 2);
	    assert (lReport.getCdSum() == ldTestSum);
	    
	    lTask = new Task();
	    lTask.startTimer();
	    lTask.stopTimer(lTask.getClStartTime() + 851378);
	    lTask.setcStrProject("testprj2");
	    ldTestSum += lTask.getCfDiffHourF();
	    
	    isAccepted = lReport.addTask(lTask);
	    
	    assert (!isAccepted);
	  }
  

  //@Test
  public void getReportSumations() {
    throw new RuntimeException("Test not implemented");
  }

  @Test
  public void setGroupingGROUP_BY() {
    ReportSumation lReport = new ReportSumation();
    lReport.setGrouping(ReportSumation.GROUP_BY.MONTH_DAY_YEAR);
    
    assert (lReport.getGroupBy() == ReportSumation.GROUP_BY.MONTH_DAY_YEAR);
  }

  //@Test
  public void setGroupingString() {
    throw new RuntimeException("Test not implemented");
  }
}
